1
|
|
|
/** |
2
|
|
|
* Service authenticator |
3
|
|
|
* |
4
|
|
|
* @since 1.0.0 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
4 |
|
const StatusType = require('../repository/StatusType'); |
8
|
4 |
|
const DeviceType = require('../repository/DeviceType'); |
9
|
|
|
|
10
|
4 |
|
const menus = [ |
11
|
|
|
{ viewName: 'StatusView', title: '공지사항 관리', url: '/' }, |
12
|
|
|
{ viewName: 'SettingView', title: '설정', url: '/settings' }, |
13
|
|
|
]; |
14
|
|
|
|
15
|
|
|
function view(request, h, childViewName, context) { |
16
|
2 |
|
const ctx = context || {}; |
17
|
|
|
ctx.viewName = childViewName; |
18
|
2 |
|
if (request.auth) { |
19
|
|
|
ctx.auth = { |
20
|
|
|
isAuthenticated: request.auth.isAuthenticated, |
21
|
|
|
username: request.auth.credentials ? request.auth.credentials.username : undefined, |
22
|
|
|
}; |
23
|
|
|
} |
24
|
|
|
ctx.menus = menus; |
25
|
|
|
ctx.state = `window.state = ${JSON.stringify(ctx)}`; |
26
|
|
|
return h.view('Layout', ctx); |
27
|
|
|
} |
28
|
|
|
|
29
|
4 |
|
module.exports = [ |
30
|
|
|
{ |
31
|
|
|
method: 'GET', |
32
|
|
|
path: '/', |
33
|
|
|
handler: (request, h) => Promise.all([StatusType.find(), DeviceType.find()]) |
34
|
|
|
.then(([statusTypes, deviceTypes]) => view(request, h, 'StatusView', { statusTypes, deviceTypes })), |
35
|
|
|
}, |
36
|
|
|
{ |
37
|
|
|
method: 'GET', |
38
|
|
|
path: '/settings', |
39
|
|
|
handler: (request, h) => view(request, h, 'SettingView', {}), |
40
|
|
|
}, |
41
|
|
|
{ |
42
|
|
|
method: 'GET', |
43
|
|
|
path: '/login', |
44
|
|
|
handler: (request, h) => (request.auth.isAuthenticated ? h.redirect('/') : view(request, h, 'Login')), |
45
|
|
|
config: { |
46
|
2 |
|
auth: { |
47
|
|
|
mode: 'try', |
48
|
|
|
}, |
49
|
|
|
}, |
50
|
|
|
}, |
51
|
|
|
{ |
52
|
|
|
method: 'GET', |
53
|
|
|
path: '/logout', |
54
|
|
|
handler: (request, h) => h.redirect('/login').unstate('token'), |
55
|
|
|
}, |
56
|
|
|
{ |
57
|
|
|
method: 'GET', |
58
|
|
|
path: '/change-password', |
59
|
|
|
handler: (request, h) => view(request, h, 'ChangePassword'), |
60
|
|
|
}, |
61
|
|
|
]; |
62
|
|
|
|